import ConfigParser

class config:
    def __init__(self):
        parser = ConfigParser.ConfigParser()
        parser.read('camproxy.conf')
        self.http_port = parser.getint('camproxy', 'port')
        self.cameras = []
        for section in parser.sections():
            sp = section.split(' ')
            if sp[0] == 'camera':
                ip = parser.get(section, 'ip')
                port = parser.get(section, 'port')
                if parser.has_option(section, 'resize'):
                    resize_w, resize_h = parser.get(section, 'resize').split('x')
                else:
                    resize_w = resize_h = 0
                    
                if parser.has_option(section, 'skip_frames'):
                    skip_frames = parser.get(section, 'skip_frames')
                else:
                    skip_frames = 0
                    
                if parser.has_option(section, 'quality'):
                    quality = parser.get(section, 'quality')
                else:
                    quality = 70
                	
                if parser.has_option(section, 'request'):
                    request = parser.get(section, 'request')
                else:
                    request = "/jpeg"
                	
                if parser.has_option(section, 'login') and parser.has_option(section, 'pass'):
                    login = parser.get(section, 'login')
                    password = parser.get(section, 'pass')
                else:
                    login = password = ''
                    
                self.cameras.append({'name': sp[1], 'ip': ip, 'port': port,
                                     'resize_w': resize_w, 'resize_h': resize_h,
                                     'skip_frames':skip_frames,
                                     'quality': quality,
                                     'request': request,
                                     'login': login,
                                     'pass': password})
                
